
CREATE TABLE [dbo].[com_clientes](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[cpf] [nvarchar](11) NOT NULL,
	[rg] [nvarchar](20) NOT NULL,
	[oe] [nvarchar](10) NOT NULL,
	[rg_emissao] [date] NOT NULL,
	[nome] [nvarchar](100) NOT NULL,
	[cep] [nvarchar](8) NOT NULL,
	[numero] [int] NOT NULL,
	[complemento] [nvarchar](100) NOT NULL,
	[telefone_residencial] [nvarchar](16) NOT NULL,
	[telefone_comercial] [nvarchar](16) NOT NULL,
	[telefone_celular] [nvarchar](16) NOT NULL,
	[email] [nvarchar](100) NOT NULL,
	[ativo] [bit] NOT NULL,
 CONSTRAINT [PK_com_clientes] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[com_clientes_usuarios](
	[clienteid] [int] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[ativo] [bit] NOT NULL
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[com_clientes_usuarios]  WITH CHECK ADD  CONSTRAINT [fk_clientes] FOREIGN KEY([clienteid])
REFERENCES [dbo].[com_clientes] ([id])
GO

ALTER TABLE [dbo].[com_clientes_usuarios] CHECK CONSTRAINT [fk_clientes]
GO



CREATE TABLE [dbo].[ctr_tiposmedidores](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[unidadeid] [int] NOT NULL,
	[modelo] [nvarchar](100) NOT NULL,
	[descricao] [nvarchar](255) NOT NULL,
	[ativo] [bit] NOT NULL,
 CONSTRAINT [PK_ctr_tiposmedidores] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]



CREATE TABLE [dbo].[ctr_unidades_medidas](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[unidade] [nvarchar](100) NOT NULL,
	[ativo] [bit] NOT NULL,
 CONSTRAINT [PK_ctr_unidades_medidas] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

CREATE TABLE [dbo].[ctr_medidores](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[tiposid] [int] NOT NULL,
	[serial] [nvarchar](100) NOT NULL,
	[ativo] [bit] NOT NULL,
 CONSTRAINT [PK_ctr_medidores] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

ALTER TABLE [dbo].[ctr_medidores]  WITH CHECK ADD  CONSTRAINT [fk_tipo_medidor] FOREIGN KEY([tiposid])
REFERENCES [dbo].[ctr_tiposmedidores] ([id])
GO

ALTER TABLE [dbo].[ctr_medidores] CHECK CONSTRAINT [fk_tipo_medidor]
GO

CREATE TABLE [dbo].[ctr_medicoes](
	[id] [int] IDENTITY(1,1) NOT NULL,
	[tipomedidorid] [int] NOT NULL,
	[medidorid] [int] NOT NULL,
	[clienteid] [int] NOT NULL,
	[UserId] [uniqueidentifier] NOT NULL,
	[unidadeid] [int] NOT NULL,
	[valormedido] [numeric](8, 2) NOT NULL,
 CONSTRAINT [PK_ctr_medicoes] PRIMARY KEY CLUSTERED 
(
	[id] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO